package cn.edu.hbpu.controller.v1;

import cn.edu.hbpu.common.R;
import cn.edu.hbpu.entity.User;
import cn.edu.hbpu.service.CommonUserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author lcy
 * @date 2022/8/12 16:09
 * @description 普通用户控制器
 */
@Slf4j
@RestController
@RequestMapping("/commonUser")
public class CommonUserController {

    @Autowired
    private CommonUserService commonUserService;

    /**
     * 分页查询会员列表。实现了搜索功能
     * @param searchField
     * @param searchText
     * @param startDateTime
     * @param endDateTime
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/pagingQuery")
    public R<Page<User>> pagingQuery(String searchField, String searchText, String startDateTime, String endDateTime, @NotNull int page, @NotNull int pageSize) {
        return commonUserService.pagingQuery(searchField, searchText, startDateTime, endDateTime, page, pageSize);
    }

    /**
     * 重置用户密码
     *
     * @param userId 用户id
     * @return
     */
    @PutMapping("/resetPwd/{userId}")
    public R<String> resetPwd(@PathVariable("userId") String userId) {
        return commonUserService.resetPwd(userId);
    }

    /**
     * 修改账号状态
     *
     * @param userId
     * @param status
     * @return
     */
    @PutMapping("/{userId}/{status}")
    public R<String> changeStatus(@PathVariable("userId") String userId, @PathVariable("status") int status) {
        return commonUserService.changeStatus(userId, status);
    }

    /**
     * 删除用户
     *
     * @param userId
     * @return
     */
    @DeleteMapping("/{userId}")
    public R<String> deleteUser(@PathVariable("userId") String userId) {
        return commonUserService.deleteUser(userId);
    }
}

